var resourceArr = {};
var nowAreaPos = store.get('current_area');
var tableOrderSel; //标记资源类型 1、2、3、4、5
// var nowPageArea = [] //当前区域保存的模板信息
// var nowAreaZone = []; // 当前焦点区域数据详情
var nowAreaSelsChec = []; //记录当前选中checkbox的数据详情
var TemplateDetailsId = getUrlParam('templateDetailsId') //模板详情列表ID


//9-19单选修改
var nowRadioCheck = {}; //当前选中的radio信息
var nowPageAreaInfo = []; //当前页面数据信息
var tagNo = 0;

// 表格数据
var liveTable;
var subjectTable;
var pointTable;
var collistTable;


/**
 * setNowPageAreaInfo 初始化设置当前页面数据区域信息
 * 
 */
function initNowPageAreaInfo(){  
    nowPageAreaInfo = []; 
    for(var areaItem in window.OPTIONS){

        var shortAreaJson = {}
        if(window.OPTIONS[areaItem].count == 1){
            setNowPageAreaNull(areaItem,1)
        }else{
            var short_i = {};   
            for(var i=1;i<=window.OPTIONS[areaItem].count;i++){
                
                short_i.i = i;
                setNowPageAreaNull(areaItem,short_i.i)
               
            }
        }

    }
    // console.log(shortAreaJson)

    function setNowPageAreaNull(areaItem,num){
        shortAreaJson = {}
        shortAreaJson.id = areaItem;
        shortAreaJson.data = null;
        shortAreaJson.tagNo = num;
        nowPageAreaInfo.push(shortAreaJson)
    }
}

/**
 * 获取当前关联数据信息
 */
$('#arealinkSelBtn').on('click', function () {
    $('.table-itemSelsbox').hide();
    // 获取当前关联数据类型
    nowAreaPos = store.get('current_area');
    resourceArr.area_no = nowAreaPos;
    resourceArr.template_type = window.OPTIONS[nowAreaPos].areaType
    resourceArr.template_no = window.OPTIONS[nowAreaPos].areaId
    resourceArr.zoneId = window.OPTIONS[nowAreaPos].area

    nowAreaSelsChec = [];
    //nowAreaSelsChec = [];记录下选中状态的数据信息;
    if (!$('.radio-selectbox input[type="radio"]:checked').length >= 1) {

        layer.alert('请进行关联选择！', {
            icon: 5
        });
        return;
    } else {
        resourceArr.resource_type = $('.radio-selectbox input[type="radio"]:checked')[0].defaultValue
        resourceArr.template_typename = getDataAreaType(resourceArr.resource_type)
        $('#myModal').modal('hide');
        var nowShowTag = ' 数据类型为：' + resourceArr.template_typename + '  |  当前区域为：' + nowAreaPos;
        // var nowShowTag = ' 数据类型为：' + resourceArr.template_typename + '  |  当前区域为：' + nowAreaPos;
        $('.ibox .ibox-title h5').text(nowShowTag)
        /* 数据类型选择后操作 */
        switch (resourceArr.resource_type) {
            case "1":
                getType_Live();
                liveTable.ajax.reload();
                break;
            case "2":
                getType_subject();
                subjectTable.ajax.reload();
                break;
            case "4":
                getType_point();
                pointTable.ajax.reload();
                break;
            case "5":
                getType_collist();
                collistTable.ajax.reload();
                break;
        }
        window.OPTIONS[nowAreaPos].resourceType = resourceArr.resource_type
    }


})

/**
 * 提交保存当前数据信息
 */
$('.savebtn').on('click', function () {
    var _this = this
    // var short_resource_id = []
    tableOrderSel = resourceArr.resource_type
    // setNowAreaZone(nowDiv, nowCheckbox, 'check')
    // console.log(nowAreaSelsChec)

        if(resourceArr.resource_type == 5){
            resourceArr.resource_id = [{
                "id":nowAreaSelsChec[0].id,
                "collist_id": nowAreaSelsChec[0].collist_id
            }]
        }else{
            resourceArr.resource_id = [{"id":nowAreaSelsChec[0].id}]
        }

        
        // console.log(nowAreaSelsChec)
        // resourceArr.collist_id = nowAreaSelsChec.collist_id?nowAreaSelsChec.collist_id:null;
        resourceArr.templateDetailsId = TemplateDetailsId;
        resourceArr.tag_no = tagNo;
        // console.log(resourceArr)
        $.ajax({
            url: "/template_type/data/savedata",
            type: "post",
            data: resourceArr,
            success: function (data) {
                if (data.status == 'success') {
                    layer.msg(data.content, {
                        icon: 1,
                        time:2000       
                    });
                    $('.table-item' + tableOrderSel).hide();
                    // var short_nowDiv = $('#' + nowAreaPos); //当前模板区域存储
                    // var short_resourceSave = [];
                    // var short_resourceJon = {};

                    // window.OPTIONS[nowAreaPos].resourceInfo = nowAreaSelsChec;
                    // var shortMsg = data.data
                    
                    fillDetailTable(nowAreaSelsChec[0]);
                    saveNowDataDetail()
                } else {
                    layer.msg(data.content, {
                        icon: 2
                    })
                }
                /*var shortZoneFlag = 1
                var nowInfoSave = {
                    "zoneId": resourceArr.area_no,
                    "resourceInfo": short_resourceSave,
                    "resource": resourceArr
                }
                $.each(nowPageArea, function(ind, item) {
                    if (item.zoneId == nowInfoSave.zoneId) {
                        item.resourceInfo = nowInfoSave.resourceInfo
                        shortZoneFlag = 0
                    }
                })
                if (shortZoneFlag) {
                    nowPageArea.push(nowInfoSave)
                }*/
                // $('.table-check-all').prop('checked', false);
            },
            error: function (data) {
                layer.msg("数据存储出错", {
                    icon: 2
                })
            }
        })

})

/**
 * 重新记录当前页面中有数据的模板信息
 * 
 */
function saveNowDataDetail(del){
    // console.log(nowPageAreaInfo)
    $.each(nowPageAreaInfo,function(nowAreaIndex,nowAreaItem){
        // console.log('nowAreaItem',nowAreaItem)
        // console.log('nowAreaPos',nowAreaPos)
        // console.log('tagNo',tagNo)
        // 有数据
        if(nowAreaItem.id == nowAreaPos && nowAreaItem.tagNo == tagNo){
            /* if(del){
                nowAreaItem.data = null;
                return;
            } */
            if(del){
                nowAreaItem.data = null;
                // console.log('saveNowDataDetail 存储当前信息数据 nowAreaItem.data',nowPageAreaInfo)                
                return;
            }else{
                // console.log('nowAreaSelsChec[0]',nowAreaSelsChec[0])
                nowAreaItem.data = {
                    "name":nowAreaSelsChec[0].name,
                    "resource_id":[{"id":resourceArr.resource_id}],
                    "resource_name":resourceArr.template_typename,
                    "resource_type":resourceArr.template_type,
                    "tag_no":tagNo,
                    "title":nowAreaSelsChec[0].title,
                }
                if(resourceArr.template_type == 5){
                    nowAreaItem.resource_id = [{"id":resourceArr.resource_id,"collist_id":nowAreaSelsChec[0].collist_id}];
                }
                // console.log('saveNowDataDetail 存储当前信息数据 nowAreaItem.data',nowPageAreaInfo)
                return;

            }
        }
    })
}

//数据模板点击当前行
$('#table_livebox').on("click", 'tbody tr', function (e) {
    // console.log($(this))
    var nowRadio = $(this).find('input[type=radio][name="checkbox-live"]')
    radioClick('live',nowRadio)
});
$('#table_subjectbox').on("click", 'tbody tr', function (e) {
    // console.log($(this))
    var nowRadio = $(this).find('input[type=radio][name="checkbox-subject"]')
    radioClick('subject',nowRadio)
});
$('#table_collistbox').on("click", 'tbody tr', function (e) {
    // console.log($(this))
    var nowRadio = $(this).find('input[type=radio][name="checkbox-collist"]')
    radioClick('collist',nowRadio)
});
$('#table_pointbox').on("click", 'tbody tr', function (e) {
    // console.log($(this))
    var nowRadio = $(this).find('input[type=radio][name="checkbox-point"]')
    radioClick('point',nowRadio)
});


function radioClick(linkSelect,nowRadio){
    nowRadio.prop("checked",true)
    tableDetailChange(linkSelect, nowRadio)
}


/* $('#table_subjectbox').on("click", 'tr input[name="checkbox-subject"]', function () {
    tableDetailChange('subject', $(this))
});

$('#table_collistbox').on("click", 'tr input[name="checkbox-collist"]', function () {
    tableDetailChange('collist', $(this))
});

$('#table_pointbox').on("click", 'tr input[name="checkbox-point"]', function () {
    tableDetailChange('point', $(this))
}); */


/* 全选按钮操作 */
$('.table').on('click', 'tr input[name="check-all"]', function () {
    switch (resourceArr.resource_type) {
        case '1':
            changeAllCheck('live', $(this));
            break;
        case '2':
            changeAllCheck('subject', $(this));
            break;
        case '4':
            changeAllCheck('point', $(this));
            break;
        case '5':
            changeAllCheck('collist', $(this));
            break;
    }
})

/* 删除操作 */
$('.areaDetail').on('click', 'th.trashBtn', function (e) {
    var nowInd = $(e.target).parents('tr').index()
    var shortPostJson = {
        "area_no":nowAreaPos,
        "template_no":window.OPTIONS[nowAreaPos].areaId,
        "template_type":window.OPTIONS[nowAreaPos].areaType,
        "tag_no":tagNo,
        "templateDetailsId":TemplateDetailsId,
    }
    // console.log(shortPostJson)
    layer.msg('确定要删除?', {
        time: 0, //不自动关闭,
        btn: ['确定', '取消'],
        yes: function (index) {
            layer.close(index);
           
            // 是否向后台发送删除区域信息
            $.ajax({
                url: '/template_type/data/area/delete',
                type: 'POST',
                // dataType: 'json',
                data: shortPostJson,
                success: function(data) {
                    if (data.status == 'success') {
                        layer.msg(data.content, {
                            icon: 1,
                            time:2000
                        });
                        
                        // $(e.target).parents('tr').remove()
                        // $('#table_detail tbody').html('<tr>当前区域暂无数据信息</tr>')
                        // $('#myModal').modal('show');
                        $(e.target).parents('tr').remove()
                        fillNoneData()
                        saveNowDataDetail('delete')
                        $('#myModal').modal('show');
                        //重新拉取回填数据

                    }
                    else {
                        layer.msg(data.content, {
                            icon: 2
                        });
                    }
                },
                error: function() {
                    layer.msg("异常！",{
                        icon : 5
                    });
                }
            })
        }
    })
});

/* 更改当前模板数据信息 */
$('.detailChangeBtn').on('click', function (ind, item) {


    $('#myModal').modal('show');

})



/* 搜索按钮操作 */
$('.tables-select-search').on('click', function () {

    switch (resourceArr.resource_type) {
        case '1':
            // nowArea = '直播媒资';
            liveTable.ajax.url('/template_type/data/lives').load();
            break;
        case '2':
            // nowArea = '专题';
            subjectTable.ajax.reload();
            break;
        case '4':
            // nowArea = '点播媒资';
            pointTable.ajax.url('/template_type/data/points').load();
            break;
        case '5':
            // nowArea = '栏目列表';
            collistTable.ajax.reload();
            break;
    }
})

/* table-collists */
$('#table-collists').on('click', function () {
    collistTable.ajax.url('/template_type/data/collists').load();
})


// 获得资源类型
function getDataAreaType(area) {
    var nowArea = '';
    switch (area) {
        case '1':
            nowArea = '直播';
            break;
        case '2':
            nowArea = '专题';
            break;
        case '4':
            nowArea = '点播';
            break;
        case '5':
            nowArea = '栏目';
            break;
    }
    return nowArea;
}

/**
 * [tableDetailChange 对checkbox选择动态渲染]
 * @param  {[type]} nowDiv      [当前模板关联选择 area/collist]
 * @param  {[type]} nowCheckbox [当前点击的checkbox框]
 * @return {[type]}             [description]
 */
function tableDetailChange(nowDiv, nowCheckbox) {
    //选中状态事件处理
    // var nowZoneInfo = {} //向后台传递的数据
    // var nowZoneInfoArr = []
    // var nowAreaZone = [] //当前区域记录的数据详细信息 

        setNowAreaZone(nowDiv, nowCheckbox, 'check')

        // 对当前点击事件进行记录 
        if (!nowCheckbox.is(':checked')) {
            $('#' + nowAreaPos).find('p').html('占位符')
            $('#' + nowAreaPos).find('img').attr({
                'src': '/custom-templates/images/defaultImg2.png',
                'alt': "图片占位"
            })
            return;
        }else{
            var shortArr = []
            shortArr.push({"id":Number(nowCheckbox.attr('data-id'))})
            nowRadioCheck.id = nowCheckbox.attr('data-id');
            nowRadioCheck.resource_id = shortArr;
            nowRadioCheck.resource_type = window.OPTIONS[nowAreaPos].resourceType;
            nowRadioCheck.templateDetailsId = TemplateDetailsId;
            nowRadioCheck.tag_no = tagNo;
            nowRadioCheck.templateArea = nowAreaPos;
        }


        // nowZoneInfoArr.push({
        //     "id": nowCheckbox.attr('data-id')
        // })
        // nowZoneInfo.resource_id = nowZoneInfoArr
        // nowZoneInfo.resource_type = window.OPTIONS[nowAreaPos].resourceType
        getAreaZone(nowRadioCheck)
        // console.log(nowCheckbox.attr('data-id'))
        // setAreaZone(nowDiv)
    }
function fillNoneData(){
    if(window.OPTIONS[nowAreaPos].count>1){
        $('#' + nowAreaPos).find('li').eq(tagNo-1).find('p').html('占位符')
        $('#' + nowAreaPos).find('li').eq(tagNo-1).find('img').attr({
            'src': '/custom-templates/images/defaultImg2.png',
            'alt': "图片占位"
        })
    }else{
        $('#' + nowAreaPos).find('p').html('占位符')
        $('#' + nowAreaPos).find('img').attr({
            'src': '/custom-templates/images/defaultImg2.png',
            'alt': "图片占位"
        })
    }
}

/**
 * 点播/回看媒资
 */
function getType_Live() {
    // 跳详情模版
    $('#table_livebox').show();
}

//专题
function getType_subject() {
    // 跳转到专题模版
    $('#table_subjectbox').show();
}

//点播
function getType_point() {
    //跳媒资详情模版
    $('#table_pointbox').show();
}
// 栏目列表
function getType_collist() {
    //跳2级模版
    $('#table_collistbox').show();
}

/**
 * [getAreaZone checkbox选择，对当前模版图片、标题更新]
 * @param  {[type]} nowZoneInfo [description]
 * @return {[type]}             [description]
 */
function getAreaZone(nowRadioCheck) {
    var sendData = {
        "id":nowRadioCheck.id,
        "resource_id":nowRadioCheck.resource_id,
        "resource_type":nowRadioCheck.resource_type,
        "templateDetailsId":TemplateDetailsId,
        "tag_no":tagNo
    }
    // console.log(sendData)
    // console.log('nowRadioCheck',nowRadioCheck)
    $.ajax({
        url: "/template_type/data/infos",
        type: "get",
        data: sendData,
        success: function (data) {
            if(data.status == 'success'){
            //   console.log('渲染当前选项',data.content)   
              var data = data.content[0]
            //   console.log(data,nowAreaPos,window.OPTIONS[nowAreaPos].count)
              if(window.OPTIONS[nowAreaPos].count > 1){
                //   console.log(tagNo-1)
                  $('#' + nowAreaPos).find('li').eq(tagNo-1).find('p').html(data.title)
                  $('#' + nowAreaPos).find('li').eq(tagNo-1).find('img').attr({
                      'src': data.img
                  })
              }else{
                  $('#' + nowAreaPos).find('p').html(data.title)
                  $('#' + nowAreaPos).find('img').attr({
                      'src': data.img
                  })
              }
             /*  $.each(data, function (zoneInd, zone) {
                  if ($('#' + nowAreaPos).find('li').length >= 1) {
                      $('#' + nowAreaPos).find('li').eq(zoneInd).find('p').html(zone.title)
                      $('#' + nowAreaPos).find('li').eq(zoneInd).find('img').attr({
                          'src': zone.img
                      })
                  } else {
                      $('#' + nowAreaPos).find('p').html(zone.title)
                      $('#' + nowAreaPos).find('img').attr({
                          'src': zone.img
                      })
                  }
              }) */
            }else{
                layer.msg(data.content, {icon: 5})
                
            }
            
        },
        error:function(){
            layer.msg("当前项数据获取出错", {icon: 5})
        }
    })
}

/**
 * [fillDetailTable 填充当前页面详情数据]
 * @param  {[type]} data [需要填充的数据组]
 * @return {[type]}      [description]
 */
function fillDetailTable(details) {
    // console.log(details)
    var shortDetails = {};
    shortDetails.area_no = nowAreaPos
    shortDetails.template_no = window.OPTIONS[nowAreaPos].areaId;
    shortDetails.template_type = window.OPTIONS[nowAreaPos].areaType;
    if(!details){
        $('.nowAreaDetail .table tbody').empty();
        $('.nowAreaDetail').hide();
        return;
    }
    $('.nowAreaDetail').show();
    // $('.nowAreaDetail .table tbody').html('')
    $('.nowAreaDetail .table tbody').html('<tr>\
    <th data-areaNo='+shortDetails.area_no+' data-templateType='+shortDetails.template_type+' data-templateNo='+shortDetails.template_no+'>' + 1 + '</th>\
    <th>' + details.resource_name + '</th>\
    <th>' + details.name + '</th>\
    <th>' + details.title + '</th>\
    <th class="trashBtn"><i class="glyphicon glyphicon-trash"></i></th>\
  </tr>');
    /* $.each(data, function (ind, details) {
        $('.nowAreaDetail .table tbody').append('<tr>\
        <th>' + (ind + 1) + '</th>\
        <th>' + details.resource_name + '</th>\
        <th>' + details.name + '</th>\
        <th>' + details.title + '</th>\
        <th class="trashBtn"><i class="glyphicon glyphicon-trash"></i></th>\
      </tr>');
    }) */
    $('.nowAreaDetail').fadeIn(400)


}

/**
 * backFillDataInfo 回填数据信息
 * 
 * @param {any} data 
 */
function backFillDataInfo(contentTempNo){
    for (var areaItem in contentTempNo) {
        var short_nowDiv = $('#' + areaItem)

        if(window.OPTIONS[areaItem].count > 1){

            $.each(contentTempNo[areaItem],function(index,item){

                $.each(nowPageAreaInfo,function(nowAreaIndex,nowAreaItem){
                    // !!! 此处的index == nowAreaItem.tagNo 应该为每个标记位置id
                    // item.tag_no == nowAreaItem.tagNo
                    if(nowAreaItem.id == areaItem && item.tag_no == nowAreaItem.tagNo){
                        nowAreaItem.data = item;
                        short_nowDiv.find('li').eq(item.tag_no-1).find('p').html(item.title);
                        short_nowDiv.find('li').eq(item.tag_no-1).find('img').attr({
                            'src': item.img
                        });
                    }
                })
            })
                
            
        }else{
            $.each(nowPageAreaInfo,function(nowAreaIndex,nowAreaItem){
                // !!! 此处的index == nowAreaItem.tagNo 应该为每个标记位置id
                // item.tag_no == nowAreaItem.tagNo
                if(nowAreaItem.id == areaItem && nowAreaItem.tagNo == 1){
                    nowAreaItem.data = contentTempNo[areaItem][0];
                }
            })
            short_nowDiv.find('p').html(contentTempNo[areaItem][0].title);
            short_nowDiv.find('img').attr({
                'src': contentTempNo[areaItem][0].img
            });
        }
    }
    // console.log('nowPageAreaInfo',nowPageAreaInfo);
}
/**
 * [fillNowPageArea 填充当前页面区域]
 * @param  {[type]} fillUrl [后台获取的模版数据信息集合]
 * @return {[type]}         [当前模块区域]
 */
function fillNowPageArea(fillUrl) {
    // console.log('fillurl-ajax',TemplateDetailsId)
    $.ajax({
        url: fillUrl,
        type: "get",
        async: false,
        data:{"templateDetailsId":TemplateDetailsId},
        // data:{"template_type":"AREA","template_no":"001"},
        success: function (data) {
            if (data.status == 'success') {
                // layer.msg(data.content, {icon: 1})
                var contentTempNo = data.content.template_datas
                // console.log(contentTempNo)
                // console.log(data.content)
                //如果当前页面没有模板信息
                if(contentTempNo==null){
                    // console.log('当前页面没有模板数据信息--------')
                    return;
                }
                backFillDataInfo(contentTempNo)
                
               
               
                
                // var short_resourceList = []//模版为列表时数据组
                /* for (var areaItem in contentTempNo) {
                    window.OPTIONS[areaItem].resourceInfo = contentTempNo[areaItem]

                    // 判断是否为列表数据
                    var short_nowDiv = $('#' + areaItem)
                    var short_resourceJon = {}
                    if (short_nowDiv.find('li').length >= 1) {
                        $.each(short_nowDiv.find('li'), function (index, item) {
                            $(item).find('p').html(contentTempNo[areaItem][index].title);
                            $(item).find('img').attr({
                                'src': contentTempNo[areaItem][index].img
                            });
                        })
                    } else {
                        short_nowDiv.find('p').html(contentTempNo[areaItem][0].title);
                        short_nowDiv.find('img').attr({
                            'src': contentTempNo[areaItem][0].img
                        });
                    }
                    nowPageArea.push({
                        "zoneId": areaItem,
                        "resourceInfo": contentTempNo[areaItem]
                    })
                } */

                // console.log(nowPageArea)
                // console.log(window.OPTIONS)
            } else {
                layer.msg(data.content, {
                    icon: 2
                })
            }
        },
        error: function (data) {
            layer.msg(data.content, {
                icon: 2
            })
        }
    })
}

/**
 * [全选/反选操作]
 * @param  {[type]} checkAllDiv [当前表格说明]
 */
function changeAllCheck(checkAllDiv, nowDiv) {
    var flagCheck = 0;

    $('#table_' + checkAllDiv + ' tr input[type="checkbox"][name="checkbox-' + checkAllDiv + '"]').each(function (index, item) {
        if (nowDiv.is(':checked')) {
            if (window.OPTIONS[nowAreaPos].count == $('#table_' + checkAllDiv + 'box tr input[type="checkbox"][name="checkbox-' + checkAllDiv + '"]').length) {

                $(item).prop("checked", true);
                flagCheck = 1;
            } else {
                nowDiv.prop("checked", false);
                layer.msg("请选择" + window.OPTIONS[nowAreaPos].count + "个数据")
            }

        } else {
            $(item).prop("checked", false);

        }
    });
    if (flagCheck) {
        fillListData(checkAllDiv)
    }

}

/**
 * 多个选项数据填充
 * @param  {[type]} nowDiv [description]
 * @return {[type]}        [description]
 */
/* function fillListData(nowDiv) {
    var nowZoneInfo = {} //向后台传递的数据
    var nowZoneInfoArr = [] //向后台传递的数据数组
    if ($('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked').length == window.OPTIONS[nowAreaPos].count) {
        // 记录当前区域信息


        $.each($('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked'), function (index, item) {
            if (nowDiv == 'collist') {
                nowZoneInfoArr.push({
                    "id": $(item).attr('data-id'),
                    "collist_id": $(item).parents('tr').find('td:eq(5) span').attr('data-collistid')
                })

            } else {
                nowZoneInfoArr.push({
                    "id": $(item).attr('data-id')
                })
            }
        })
        console.log(nowZoneInfo)
        nowZoneInfo.resource_id = nowZoneInfoArr.id;
        nowZoneInfo.resource_type = window.OPTIONS[nowAreaPos].resourceType
        
        getAreaZone(nowZoneInfo)
        setAreaZone(nowDiv)
    }
} */
/* 修改记录：
   nowAreaZone 为选中的信息组

   设置 nowAreaSelsChec = [] 记录当前选中项


 */

/* 单击选中框操作 */
function setNowAreaZone(nowDiv, nowCheckbox, btnAttr) {
    var zonedataId = {}
    // var shortZoneInfo = []
    nowAreaSelsChec = []
    // console.log('单击选中框操作 --- setNowAreaZone' )
    if (btnAttr == 'check') {

        zonedataId.id = nowCheckbox.attr('data-id')
        zonedataId.name = nowCheckbox.parents('tr').find('td:eq(3)').html()
        zonedataId.title = nowCheckbox.parents('tr').find('td:eq(4)').html()
        if (nowDiv == 'collist') {
            zonedataId.collistId = nowCheckbox.parents('tr').find('td:eq(5) span').attr('data-collistid')
            nowAreaSelsChec.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title,
                "collist_id": zonedataId.collistId
            })
        } else {
            nowAreaSelsChec.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title
            })


        }
        // console.log('nowAreaSelsChec',nowAreaSelsChec)

    } else if (btnAttr == 'cancel') {
        nowAreaSelsChec=[]
        
    }

    /* if (btnAttr == 'check') {
        
        zonedataId.id = nowCheckbox.attr('data-id')
        zonedataId.name = nowCheckbox.parents('tr').find('td:eq(3)').html()
        zonedataId.title = nowCheckbox.parents('tr').find('td:eq(4)').html()
        if (nowDiv == 'collist') {
            zonedataId.collistId = nowCheckbox.parents('tr').find('td:eq(5) span').attr('data-collistid')
            nowAreaSelsChec.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title,
                "collist_id": zonedataId.collistId
            })
        } else {
            nowAreaSelsChec.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title
            })
        }

    } else if (btnAttr == 'cancel') {
        nowAreaSelsChec = [];
    } */
    
    /* if (btnAttr == 'check') {

        zonedataId.id = nowCheckbox.attr('data-id')
        zonedataId.name = nowCheckbox.parents('tr').find('td').eq(3).html()
        zonedataId.title = nowCheckbox.parents('tr').find('td:eq(4)').html()
        if (nowDiv == 'collist') {
            zonedataId.collistId = nowCheckbox.parents('tr').find('td:eq(5) span').attr('data-collistid')
            nowAreaSelsChec.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title,
                "collist_id": zonedataId.collistId
            })
        } else {
            nowAreaSelsChec.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title
            })


        }

    } else if (btnAttr == 'cancel') {
        nowAreaSelsChec.each(function (index, item) {
            if (item.id == nowCheckbox.attr('data-id')) {
                delete nowAreaSelsChec[index];
            }
            return;
        })
    } */

}

/**
 * [setAreaZone 存储当前数据详情]
 * @param {[type]} nowDiv [description]
 */
/* function setAreaZone(nowDiv) {
    var zonedataId = {}
    var shortZoneInfo = []

    $.each($('#table_' + nowDiv + 'box input[name="checkbox-' + nowDiv + '"]:checked'), function (index, item) {
        zonedataId.id = $(item).attr('data-id')
        zonedataId.name = $(item).parents('tr').find('td:eq(3)').html()
        zonedataId.title = $(item).parents('tr').find('td:eq(4)').html()

        if (nowDiv == 'collist') {

            shortZoneInfo.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title,
                "collist_id": $(item).parents('tr').find('td:eq(5) span').attr('data-collistid')
            })

        } else {
            shortZoneInfo.push({
                "id": zonedataId.id,
                "resource_name": resourceArr.template_typename,
                "name": zonedataId.name,
                "title": zonedataId.title
            })
        }
    })
    nowAreaZone = shortZoneInfo;
    nowAreaSelsChec = shortZoneInfo;
    window.OPTIONS[nowAreaPos].resourceInfo = nowAreaZone

} */
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}


// 刷新页面操作
function runRefresh(nowAreaTable) {
    switch (nowAreaTable) {
        case '1':
            // nowArea = '直播媒资';
            liveTable.ajax.reload();
            break;
        case '2':
            // nowArea = '专题';
            subjectTable.ajax.reload();
            break;

        case '4':
            // nowArea = '点播媒资';
            pointTable.ajax.reload();
            break;
        case '5':
            // nowArea = '栏目列表';
            collistTable.ajax.reload();
            break;
    }
}

// 选择的区域模版焦点操作
$('.removeFocus').on('click', function () {
    $('#' + nowAreaPos).removeClass('activefocus')
})

// 取消按钮操作
$('.table-back-btn').on('click', function () {
    /* var locat = String(location.href)
    var locaArr = locat.split("/");
    var nowLocation = '';
    for (var i in locaArr) {

        nowLocation += locaArr[i] + '/';
        if (locaArr[i] == 'admin') {
            nowLocation += 'operation/content_templates'
            location.href = nowLocation;
            return;
        }
    } */
    history.go(-1)
})

// 模板区域显示


// 点击跳转模板
/* $('#custom-template-wrap').on('click', '#p0y1 li', function () {
    var ind = $(this).index();
    var locat = String(location.href)
    var locaArr = locat.split("/");
    var nowLocation = '';
    for (var i in locaArr) {

        nowLocation += locaArr[i] + '/';
        if (locaArr[i] == 'AREA') {
            nowLocation += '00' + (ind + 1) + '/create'
            if (location.href == nowLocation) return;
            location.href = nowLocation;
            return;
        }
    }
}) */